package com.anyou.mall.order.orderServe.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.anyou.common.annotation.ShopScope;
import com.anyou.mall.order.orderServe.vo.OrderServiceLogisticsVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.order.orderServe.domain.OrdOrderServe;
import com.anyou.mall.order.orderServe.service.IOrdOrderServeService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 订单售后Controller
 *
 * @author ruoyi
 * @date 2022-03-23
 */
@Api(tags = "订单售后")
@RestController
@RequestMapping("/serve/ordServe")
public class OrdOrderServeController extends BaseController
{
    @Autowired
    private IOrdOrderServeService ordOrderServeService;

    /**
     * 查询订单售后列表
     */
    @ApiOperation("查询订单售后列表")
    @PreAuthorize("@ss.hasPermi('serve:ordServe:list')")
    @GetMapping("/list")
    @ShopScope(baseTableAlias="a")
    public TableDataInfo<List<OrdOrderServe>> list(OrdOrderServe ordOrderServe)
    {
        startPage();
        List<OrdOrderServe> list = ordOrderServeService.selectOrdOrderServeList(ordOrderServe);
        return getDataTable(list);
    }

    /**
     * 导出订单售后列表
     */
    @ApiOperation("导出订单售后列表")
    @PreAuthorize("@ss.hasPermi('serve:ordServe:export')")
    @Log(title = "订单售后", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ShopScope(baseTableAlias="a")
    public void export(OrdOrderServe ordOrderServe,HttpServletResponse response)
    {
        List<OrdOrderServe> list = ordOrderServeService.selectOrdOrderServeList(ordOrderServe);
        ExcelUtil<OrdOrderServe> util = new ExcelUtil<OrdOrderServe>(OrdOrderServe.class);
        util.exportExcel(response, list, "订单售后数据");
    }

    /**
     * 获取订单售后详细信息
     */
    @ApiOperation("获取订单售后详细信息")
    @PreAuthorize("@ss.hasPermi('serve:ordServe:query')")
    @GetMapping(value = "/{orderServeId}")
    public ApiResult<OrdOrderServe> getInfo(@PathVariable("orderServeId") Long orderServeId)
    {
        return ApiResult.success(ordOrderServeService.selectOrdOrderServeByOrderServeId(orderServeId));
    }

    /**
     * 新增订单售后
     */
    @ApiOperation("新增订单售后")
    @PreAuthorize("@ss.hasPermi('serve:ordServe:add')")
    @Log(title = "订单售后", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody OrdOrderServe ordOrderServe)
    {
        return ApiResult.success(ordOrderServeService.insertOrdOrderServe(ordOrderServe));
    }

    /**
     * 修改订单售后
     */
    @ApiOperation("修改订单售后")
    @PreAuthorize("@ss.hasPermi('serve:ordServe:edit')")
    @Log(title = "订单售后", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody OrdOrderServe ordOrderServe)
    {
        return ApiResult.success(ordOrderServeService.updateOrdOrderServe(ordOrderServe));
    }

    /**
     * 删除订单售后
     */
    @ApiOperation("删除订单售后")
    @PreAuthorize("@ss.hasPermi('serve:ordServe:remove')")
    @Log(title = "订单售后", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderServeIds}")
    public ApiResult remove(@PathVariable Long[] orderServeIds)
    {
        return ApiResult.success(ordOrderServeService.deleteOrdOrderServeByOrderServeId(orderServeIds));
    }

    /**
     * 售后订单审核
     */
    @ApiOperation("售后订单审核")
    @PreAuthorize("@ss.hasPermi('order:service:audit')")
    @Log(title = "售后订单审核", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/audit")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "serveId", dataType = "Long", required = true, value = "售后订单编号"),
            @ApiImplicitParam(name = "serveAuditStatus", dataType = "String", required = true, value = "售后审核状态（0等待商家受理 ，1商家同意申请，2拒绝申请）"),
            @ApiImplicitParam(name = "auditRemark", dataType = "String", required = false, value = "备注理由")
    })
    public ApiResult audit(@RequestParam(value = "serveId") Long serveId, @RequestParam(value = "serveAuditStatus") String serveAuditStatus, @RequestParam(value = "auditRemark", required = false) String auditRemark) {
        return ApiResult.success(ordOrderServeService.audit(serveId,serveAuditStatus,auditRemark));
    }

    /**
     * 售后订单完成
     */
    @ApiOperation("售后订单完成")
    @PreAuthorize("@ss.hasPermi('order:service:finish')")
    @Log(title = "售后订单完成", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/finish")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "serveId", dataType = "Long", required = true, value = "售后订单编号")
    })
    public ApiResult finish(@RequestParam(value = "serveId") Long serveId) {

        return ApiResult.success(ordOrderServeService.finish(serveId));
    }

    /**
     * 售后订单发货
     */
    @ApiOperation("售后订单发货")
    @PreAuthorize("@ss.hasPermi('order:service:sendGoods')")
    @Log(title = "售后订单发货", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/sendGoods")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "serveId", dataType = "Long", required = true, value = "售后订单编号"),
            @ApiImplicitParam(name = "logisticsId", dataType = "Long", required = false, value = "快递公司ID"),
            @ApiImplicitParam(name="logisticsName",dataType="String",required=false,value="物流名称"),
            @ApiImplicitParam(name = "logisticsNo", dataType = "String", required = true, value = "快递单号")
    })
    public ApiResult sendGoods(@RequestParam(value = "serveId") Long serveId,
                               @RequestParam(value = "logisticsId",required = false) Long logisticsId,
                               @RequestParam(value = "logisticsName") String logisticsName,
                               @RequestParam(value = "logisticsNo") String logisticsNo) {
        return ordOrderServeService.sendGoods(serveId, logisticsId,logisticsName, logisticsNo);
    }

    /**
     * 获取售后订单物流信息
     */
    @ApiOperation("获取售后订单物流信息")
    @PreAuthorize("@ss.hasPermi('order:service:LogisticsInfo')")
    @PostMapping(value = "/LogisticsInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderServeId", dataType = "Long", required = true, value = "售后订单号")
    })
    public ApiResult<OrdOrderServe> LogisticsInfo(@RequestParam(value = "orderServeId") Long orderServeId)
    {
        return ordOrderServeService.getLogisticsInfo(orderServeId);
    }
}
